class UserSessionsController < ApplicationController

  before_filter :require_no_user, :only => :new
  before_filter :require_user,    :only => :destroy

  def show
    redirect_to :action => :new
  end

  def new
    @user_session = UserSession.new
  end

  def create
    @user_session = UserSession.new(params[:user_session])

    if @user_session.save
      flash[:info] = "Byli jste úspěšně přihlášeni."

      #Save user's email into cookie, and fill login form next time
      cookies.permanent[:user_email] = params[:user_session][:email]

      redirect_back_or_default user_path
    else
      render :action => :new
    end
  end

  def destroy
    current_user_session.destroy rescue nil
    
    flash[:info] = "Byli jste úspěšně odhlášeni."
    
    redirect_back_or_default login_path
  end

  def remember_me_for
    1.month
  end
end
